package cn.pping.web.controller;


import cn.pping.exception.GlobalEnumCode;
import cn.pping.exception.GlobalException;
import cn.pping.result.JSONResult;
import cn.pping.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/verifycode")
@RestController
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService iVerifyCodeService;

    /**
     * @Title: getVerifyCode图形验证码
     * @Description: codeBase
     * @Author: Pan
     * @Version: 1.0
     * @Date: 2022/7/28 15:09
     * @Parameters: [key]
     * @Return cn.pping.basic.util.JSONResult
     */

    @GetMapping("/imageCode/{key}")
    public JSONResult getVerifyCode(@PathVariable("key") String key){
        if (true) {
            String codeBase = iVerifyCodeService.getVerifyCode(key);
            // 将数据封装给前端
            return JSONResult.success(codeBase);
        } else {
            throw new GlobalException(GlobalEnumCode.ERROR);
        }
    }

    /**
     * @Title: 注册手机验证码
     * @Description: 手机验证码
     * @Author: Pan
     * @Version: 1.0
     * @Date: 2022/8/1 17:35
     * @Parameters: [map]
     * @Return cn.pping.basic.util.JSONResult
     */

    @GetMapping("/sendSmsCode/{moblie}")
    public JSONResult sendSmsCode(@PathVariable("moblie") String moblie) {
            iVerifyCodeService.sendSmsCode(moblie);
            // 将数据封装给前端
            return JSONResult.success();
    }
}
